﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Devtm.ServiceModel.Proxy;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;

namespace Devtm.ServiceModel.Resolver.Connectors
{
    internal class ServiceEndpointConnector : IServiceConnector
    {


        public ServiceEndpointConnector(IServiceResolver resolver, ServiceEndpoint address, params IEndpointBehavior[] behaviors)
        {
            Resolver = resolver;
            Address = address;
            Behaviors = behaviors;
        }
        

        public object[] Parameters() 
        {
            UsedCount++;
            return new object[] { Address, Behaviors }; 
        }


        public IServiceResolver Resolver { get; private set; }
        public ServiceEndpoint Address { get; set; }
        public IEndpointBehavior[] Behaviors { get; set; }
        public int UsedCount { get; private set; }


        public override int GetHashCode()
        {
            string k = Address.Address.Uri.AbsoluteUri + Address.Contract.Name + Address.Binding.GetType().Name;
            return k.GetHashCode();
        }

        public override bool Equals(object obj)
        {
            return obj.GetHashCode() == GetHashCode();
        }

        public Uri Uri
        {
            get { return Address.Address.Uri; }
        }

        public Binding Binding
        {
            get { return Address.Binding; }
        }

    }
}
